package com.cas.object;

import java.util.ArrayList;
import java.util.List;



public class Download_Plu_Commond{
	private static final long serialVersionUID = 1L;

	static List<byte[]> makeCommondToScale(List<Plu> plulist) throws Exception
	{
	    List<byte[]> rSendBufList = new ArrayList<byte[]>();
	    for(int j = 0; j < plulist.size(); j++)
	    {
	        Plu plu = plulist.get(j);
	        byte[] rSendBuf = new byte[162];
	        for(int i=0;i<162;i++) rSendBuf[i]='\0';
	        byte[] rBuf;
	        int nCnt = 0;
	        short wdData;
	        int dwData;
	        short departNo = 1;
	        int group_no = plu.group_no;
	        int pluno=plu.plu_no;
	        String pluname = plu.item_name;
	        int itemcode=Integer.parseInt(plu.item_code);

	        rSendBuf[nCnt++]='W';
	        rSendBuf[nCnt++]='L';

	        nCnt += 4;
	        rSendBuf[nCnt++]=',';

	        //plu structure length
	        wdData = (short)149;
	        rBuf = Common_tool.getBytes((Common_tool.swap(wdData)));
	        //rSendBuf.replace(nCnt,rBuf.size(),rBuf);
	        System.arraycopy(rBuf, 0, rSendBuf, nCnt, rBuf.length);
	        nCnt += 2;

	        rSendBuf[nCnt++] = ':';

	        //data structure
	        //department no,in default departno=1
	        wdData = departNo;
	        rBuf = Common_tool.getBytes(Common_tool.swap(wdData));
	        //rSendBuf.replace(nCnt,rBuf.size(),rBuf);
	        System.arraycopy(rBuf, 0, rSendBuf, nCnt, rBuf.length);
	        nCnt += 2;
	        //plu num
	        dwData = pluno;
	        rBuf = Common_tool.getBytes(Common_tool.swap(dwData));
	        System.arraycopy(rBuf, 0, rSendBuf, nCnt, rBuf.length);
	        nCnt += 4;
	        //plu type 1=weight 2=amount
	        rSendBuf[nCnt++]=(char)0x01;
	        //name1
//	        QTextCodec *codec = QTextCodec::codecForName("GBK");
//	        rBuf = codec->fromUnicode(pluname);
	        rBuf = pluname.getBytes("GBK");
	        System.arraycopy(rBuf, 0, rSendBuf, nCnt, rBuf.length);
	        nCnt += 40;
	        //name2
	        rBuf = pluname.getBytes("GBK");
	        System.arraycopy(rBuf, 0, rSendBuf, nCnt, rBuf.length);
	        nCnt += 40;
	        //name3
	        rBuf = pluname.getBytes("GBK");
	        System.arraycopy(rBuf, 0, rSendBuf, nCnt, rBuf.length);
	        nCnt += 5;

	        //group
	        wdData = (short)group_no;
	        rBuf = Common_tool.getBytes(Common_tool.swap(wdData));
	        System.arraycopy(rBuf, 0, rSendBuf, nCnt, rBuf.length);
	        nCnt += 2;

	        //label1
	        nCnt += 2;

	        //label2
	        nCnt += 2;

	        //origin
	        nCnt += 2;

	        //weight unit
	        nCnt += 1;
	        //fixed weight
	        nCnt += 4;
	        //itemcode
	        dwData = itemcode;
	        rBuf = Common_tool.getBytes(Common_tool.swap(dwData));
	        System.arraycopy(rBuf, 0, rSendBuf, nCnt, rBuf.length);
	        nCnt += 4;
	        //pieces
	        nCnt += 2;
	        //qsymbol
	        nCnt += 1;
	        //fixed price type
	        nCnt += 1;

	        //unit price
	        dwData = 1000;
	        rBuf = Common_tool.getBytes(Common_tool.swap(dwData));
	        System.arraycopy(rBuf, 0, rSendBuf, nCnt, rBuf.length);
	        nCnt += 4;

	        //tax no first tax no,last 3,reserved
	        nCnt += 4;

	        //tare weight
	        nCnt += 4;

	        //tare no
	        nCnt += 1;

	        //barcode1
	        nCnt += 2;

	        //barcode2
	        nCnt += 2;

	        //produce date
	        nCnt += 2;

	        //packed date
	        nCnt += 2;

	        //packed time
	        nCnt += 1;

	        //sell date
	        nCnt += 4;

	        //sell time
	        nCnt += 1;

	        //msg no
	        nCnt += 2;

	        //traceability no
	        nCnt += 2;

	        //nutrifact no
	        nCnt += 2;

	        //sale msg
	        nCnt += 1;

	        //direct msg no
	        nCnt += 2;

	        //:
	        rSendBuf[nCnt++]=':';
	        //check sum
	        rSendBuf[nCnt++]=Common_tool.getCheckSum(rSendBuf,nCnt,2);
	        //end flag
	        rSendBuf[nCnt++]=(char)0x0D;
	        rSendBufList.add(rSendBuf);
	    }
	    return rSendBufList;
	}

}
